package com.toby.service.impl;

import com.toby.dao.AccountDao;
import com.toby.service.LogService;
import com.toby.service.PayService;
import com.toby.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @desc: 支付Service
 * @author: toby
 * @date: 2019/10/8 22:33
 */
@Service
public class PayServiceImpl implements PayService {
    @Autowired
    private AccountDao accountDao;
    @Autowired
    private ProductService productService;
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void pay(String accountId, double money, int productId) {
        //扣库存
        productService.updateProductStore(productId);
        //System.out.println(1/0);
        //扣账户
        accountDao.updateAccountBalance(accountId,money);
    }
}
